<template>
  <el-container style="height: 720px; border: 1px solid #eee">
    <el-aside width="175px" style="background-color: rgb(238, 241, 246)">
      <el-menu background-color="#ffffff" text-color="#303133" active-text-color="#405EFF" router>
        <el-submenu :index="menu.id" v-for="menu in menuList" :key="menu.id">
          <template slot="title">
            <i :class="menu.icon"></i>
            {{menu.menuName}}
          </template>

          <el-menu-item
            :index="'/'+itemMenu.url"
            v-for="itemMenu in menu.children"
            :key="itemMenu.id"
          >{{itemMenu.menuName}}</el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header style="text-align: right; font-size: 12px">
        <el-dropdown>
          <i class="el-icon-setting" style="margin-right: 12px"></i>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="loginOut">退出</el-dropdown-item>
            <el-dropdown-item @click.native="test">111</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <span>徐孝力</span>
      </el-header>

      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<style>
.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>
<script>
export default {
  name: "home",
  data() {
    return {
      menuList: []
    };
  },
  created: function() {
    this.$http.get("/api/system/menu/menus").then(res => {
      let result = res.data;
      if (result.code != 0) {
        this.$message({
          message: "操作失败",
          type: "error"
        });
      } else {
        this.menuList = result.data;
      }
    });
  },
  methods: {
    loginOut() {
      this.$http.post("/api/loginout", null).then(res => {
        let result = res.data;
        if (result.code == 0) {
          this.$message({
            message: "操作成功",
            type: "success"
          });
          window.sessionStorage.clear();
          this.$router.push("/login");
        } else {
          this.$message({
            message: "操作失败",
            type: "error"
          });
        }
      });
    }
  }
};
</script>
